package com.jtjrenren.android.taxi.driver.bean.api;

import com.google.gson.Gson;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

/**
 * Created by Administrator on 2016/9/7.
 */

public class ApiResultCommon<T> {

    /**
     * code : 1
     * desc :
     * data : []
     */

    private int code;
    private String desc;
    private List<T> data;

    public void setCode(int code) {
        this.code = code;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public List<T> getData() {
        return data;
    }

    public static ApiResultCommon fromJson(String json, Class clazz) {
        Gson gson = new Gson();
        Type objectType = type(ApiResultCommon.class, clazz);
        return gson.fromJson(json, objectType);
    }

    static ParameterizedType type(final Class raw, final Type... args) {
        return new ParameterizedType() {
            public Type getRawType() {
                return raw;
            }

            public Type[] getActualTypeArguments() {
                return args;
            }

            public Type getOwnerType() {
                return null;
            }
        };
    }
}
